﻿using Loki.Client;

namespace TestLog
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            var url = "http://localhost:3100";
            //url = "http://10.0.10.142:3100";
            var client = new LokiClient(url);

            var app = "qms";

            await client.LogDebugAsync("debug", app);
            await client.LogInfoAsync("info", app);
            await client.LogWarningAsync("warning", app);
            await client.LogErrorAsync("error", app);
            await client.LogFatalAsync("fatal", app);
            await client.LogCriticalAsync("LogCriticalAsync", app);

            await client.LogDebugAsync(new { id = 1, name = "李四", age = 10, money = 112.2 }, app);
            await client.LogErrorAsync(new Exception("这是个错误"), app);

            //Test Single Insert
            var entity = new LokiLogEntity
            {
                LogLevel = LokiLogLevel.Info,
                App = app,
                Message = "Log单个信息"
            };
            await client.LogAsync(entity);

            //Test Bulk Insert
            var app2 = "wms";
            List<LokiLogEntity> list = [
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Debug,
                    App = app,
                    Message = "Debug",
                    Time = DateTimeOffset.UtcNow
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Debug,
                    App = app,
                    Message = "Debug2"
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Critical,
                    App = app,
                    Message = new{ id=1,name="Critical你好",address ="福建",money = 11.99}
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Info,
                    App = app,
                    Message = "Info"
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Warning,
                    App = app,
                    Message = "Warning"
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Error,
                    App = app2,
                    Message = "Error"
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Fatal,
                    App = app2,
                    Message = "Fatal"
                },
                new LokiLogEntity
                {
                    LogLevel = LokiLogLevel.Info,
                    App = app2,
                    Message = new{ id=1,name="你好",address ="厦门",money = 11.99}
                }
            ];
            await client.LogAsync(list);


            var queue = new LokiQueue(client);

            _ = Task.Run(async () =>
            {
                while (true)
                {
                    queue.AddLog(new LokiLogEntity
                    {
                        LogLevel = LokiLogLevel.Debug,
                        App = app,
                        Message = "Debug" + DateTime.Now.Microsecond,
                        Time = DateTimeOffset.UtcNow
                    });

                    await Task.Delay(100);
                }
            });


            Console.WriteLine("Hello, World!");
            Console.ReadKey();
        }
    }
}
